package com.jeecg.p3.system.service.impl;

import com.jeecg.p3.system.dao.ProductCategoryDao;
import com.jeecg.p3.system.entity.Product;
import com.jeecg.p3.system.entity.ProductCategory;
import com.jeecg.p3.system.service.ProductCategoryService;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: jeewx-boot-parent
 * @description: 产品类别业务处理类
 * @author: binbin
 * @create: 2020-09-21 09:23
 */
@Service("productCategoryService")
public class ProductCategoryServiceImpl implements ProductCategoryService {

    @Resource
    private ProductCategoryDao productCategoryDao;

    @Override
    public void doAdd(ProductCategory productCategory) {

        productCategoryDao.insert(productCategory);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void doEdit(ProductCategory productCategory) {
        productCategoryDao.update(productCategory);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void doDelete(Long id) {
        productCategoryDao.delete(id);
    }

    @Override
    public ProductCategory queryById(Long id) {
        return productCategoryDao.get(id);
    }

    @Override
    public PageList<ProductCategory> queryPageList(PageQuery<ProductCategory> pageQuery) {
        PageList<ProductCategory> result = new PageList<>();
        Integer itemCount = productCategoryDao.count(pageQuery);
        PageQueryWrapper<ProductCategory> wrapper = new PageQueryWrapper<ProductCategory>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<ProductCategory> list = productCategoryDao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }
}
